package com.chen.bpsptsystem;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @CLASSNAME MyWebAppConfigurer
 * @DESCRIPTION 图片上传资源配置
 * @AUTHOR chen
 * @DATE 2018-12-04 14:36
 **/
@Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler( "/image/**" ).addResourceLocations( "file:/root/pic/" );
        registry.addResourceHandler( "/image/**" ).addResourceLocations( "file:D:/profile/" );
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        WebMvcConfigurer.super.addResourceHandlers( registry );
    }

    // 跨域请求
    static final String ORIGINS[] = new String[]{"GET", "POST", "PUT", "DELETE"};

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping( "/**" ).allowedOrigins( "*" ).allowCredentials( true ).allowedMethods( ORIGINS ).maxAge( 3600 );
    }
}
